<?php

use Biz\model\activity\SNJActivityRecord;

/**
 * @deprecated
 * 三棱镜 广告活动记录
 * Class SNJRecordAction
 */
class SNJDesignerRecordAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_REGISTER;

    public function main()
    {
        $data = [];
        $data['area'] = $this->getRequest()->getPost('area');
        $data['area_name'] = $this->getRequest()->getPost('area_name');
        $data['working_year'] = $this->getRequest()->getPost('working_year');//从业年限
        $data['award_experience'] = $this->getRequest()->getPost('award_experience');//获奖经历
        $data['selected_case'] = $this->getRequest()->getPost('selected_case'); // 选择案例
        $data['deco_style'] = $this->getRequest()->getPost('deco_style'); //装修风格
        $data['effect_picture'] = $this->getRequest()->getPost('effect_picture');//效果图
        // 判断是否填写房屋位置
        if (empty($data['area'])) {
            throw new \Exception('请输入位置', self::CODE_ERROR_VIEW_TOSTA);
        }
        // 判断地区格式是否正确
        if (strpos($data['area'], ',')) {
            $areas = explode(',', $data['area']);
            foreach ($areas as $key => $value) {
                if (! is_numeric($value)) {
                    throw new \Exception('位置输入格式错误', self::CODE_ERROR_VIEW_TOSTA);
                }
            }
        } else {
            throw new \Exception('位置输入格式错误', self::CODE_ERROR_VIEW_TOSTA);
        }

        // 判断是否填写房屋位置
        if (! is_numeric($data['working_year'])) {
            throw new \Exception('工作年限只能是输入数字', self::CODE_ERROR_VIEW_TOSTA);
        }

        if(empty($data['award_experience'])){
            throw new \Exception('获奖经历缺失', self::CODE_ERROR_VIEW_TOSTA);
        }


//        if(empty($data['selected_case'])){
//            throw new \Exception('缺失案例', self::CODE_ERROR_VIEW_TOSTA);
//        }
        if(empty($data['deco_style'])){
            throw new \Exception('缺失装修风格', self::CODE_ERROR_VIEW_TOSTA);
        }
        $inserInfo = [];
        $inserInfo['uid'] = $this->uid;
        $inserInfo['type'] = SNJActivityRecord::DESIGN_TYPE;
        $inserInfo['extend_info'] = json_encode($data);
        $result =  SNJActivityRecord::inserRecord($inserInfo);
        if($result){
            $this->setSuccess();
        }else{
            throw new \Exception('报名失败', self::CODE_ERROR_VIEW_TOSTA);
        }
    }
}